package com.tiantian.controller.visualization;

import com.tiantian.mapper.BlogMapper;
import com.tiantian.mapper.CountTypeMapper;
import com.tiantian.mapper.UserCommentMapper;
import com.tiantian.pojo.visualization.BlogCountVO;
import com.tiantian.pojo.visualization.CountStar;
import com.tiantian.pojo.visualization.CountType;
import com.tiantian.pojo.Result;
import com.tiantian.utils.UserHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/count")
@CrossOrigin
public class CountController {
    @Autowired
    private CountTypeMapper countTypeMapper;

    @Autowired
    private BlogMapper blogMapper;

    @Autowired
    private UserCommentMapper userCommentMapper;

    @GetMapping("/label")
    public Result getCountLabel(){
        List<CountType> countTypes = countTypeMapper.countType();
        return Result.ok(countTypes);
    }

    @GetMapping("/star/me")
    public Result getStarByLabelAndUid(){
        List<CountStar> CountStars = countTypeMapper.countStarByLoginUserUid(UserHolder.getUid());
        return Result.ok(CountStars);
    }

    @GetMapping("/get-blog-count")
    public Result getTotal(){
        Integer uid = UserHolder.getUid();
        // 获取评论数量
        Integer commentCount =  userCommentMapper.getCountCommentByUid(uid);
        // 获取点赞 评论 收藏数量
        BlogCountVO blogCountVO = blogMapper.getBlogCountByUid(uid);
        // 封装数据
        blogCountVO.setCommentCount(commentCount);
        return Result.ok(blogCountVO);
    }
}
